package com.itheima.wordcount;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class WordCountMapperTask extends Mapper<LongWritable,Text,Text, IntWritable> {

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        System.out.println("偏移量为"+key.get());

        //1、获取每一行的数据
        String line = value.toString();

        if(line!=null && !"".equals(line)){
            //2、对数据切割
            String[] words = line.split(" ");
            //为每一个设置一个数值1，然后进行输出操作
            for(String word:words){
                context.write(new Text(word),new IntWritable(1));
            }
        }

    }
}
